import {message} from 'antd';
import {formatMessage} from './intl';

export const updateValidator = data => {
    const emptyErrors = [];
    const dealerServiceInformation = data.dealerServiceInformation;
    const partPriceCoefficientDetail = data.partPriceCoefficientDetail;
    const specialPartPriceCoefficient = data.specialPartPriceCoefficient;
    if(dealerServiceInformation.some(d => !d.brandId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.brandId',
                defaultMessage: '品牌'
            })
        );
    if(dealerServiceInformation.some(d => !d.tradeMethodId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.tradeMethodId',
                defaultMessage: '贸易方式'
            })
        );
    if(dealerServiceInformation.some(d => !d.currency))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.currency',
                defaultMessage: '币种'
            })
        );
    if(dealerServiceInformation.some(d => !d.cbuIntervalDate))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.cbuIntervalDate',
                defaultMessage: 'CBU间隔月份'
            })
        );
    if(dealerServiceInformation.some(d => !d.kdIntervalDate))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.kdIntervalDate',
                defaultMessage: 'KD间隔月份'
            })
        );
    if(dealerServiceInformation.some(d => !d.exAuthorizatedLimit))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.exAuthorizatedLimit',
                defaultMessage: '备件超授权额度'
            })
        );
    if(dealerServiceInformation.some(d => d.isNeedApproved === null))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.isNeedApproved',
                defaultMessage: '是否需要自动审核'
            })
        );
    if(dealerServiceInformation.some(d => !d.submitTimeLimit))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.submitTimeLimit',
                defaultMessage: '索赔单提交时限'
            })
        );

    if(dealerServiceInformation.some(d => !d.price))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.price',
                defaultMessage: '工时单价'
            })
        );

    if(dealerServiceInformation.some(d => !d.mgmtFeeRate))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.mgmtFeeRate',
                defaultMessage: '备件管理费率'
            })
        );
    if(dealerServiceInformation.some(d => !d.claimPITitle))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.claimPITitle',
                defaultMessage: '索赔PI标题'
            })
        );
    if(partPriceCoefficientDetail.some(d => !d.brandId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.brandId',
                defaultMessage: '品牌'
            })
        );
    if(partPriceCoefficientDetail.some(d => !d.priceRate))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.priceRate',
                defaultMessage: '价格系数'
            })
        );
    if(specialPartPriceCoefficient.some(d => !d.brandId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.brandId',
                defaultMessage: '品牌'
            })
        );
    if(specialPartPriceCoefficient.some(d => !d.partId))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.partId',
                defaultMessage: '备件编号'
            })
        );
    if(specialPartPriceCoefficient.some(d => !d.priceRate))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.priceRate',
                defaultMessage: '价格系数'
            })
        );
    if(specialPartPriceCoefficient.some(d => !d.startTime))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.startTime',
                defaultMessage: '生效日期'
            })
        );
    if(specialPartPriceCoefficient.some(d => !d.endTime))
        emptyErrors.push(
            formatMessage({
                id: 'validator.message.endTime',
                defaultMessage: '失效日期'
            })
        );
    if(emptyErrors.length > 0) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    if(specialPartPriceCoefficient.some(d => d.endTime < d.startTime)) {
        message.warning(`${emptyErrors.join('，')}${formatMessage({
            id: 'validator.notbefore',
            defaultMessage: '失效日期不可在生效日期之前!'
        })}`);
        return false;
    }
    return true;
};
